import util from "../utils/util.js";
class LoginModel {

    //获取个人数据
    getUserInfo() {
        return new Promise((resolve) => {
                wx.getSetting({
                    success: function (res) {
                        resolve(res);
                    }
                });
            })
            .then(
                res => {
                    if (res.authSetting["scope.userInfo"]) {
                        return new Promise((resolve) => {
                            wx.getUserInfo({
                                success(res) {
                                    resolve(res);
                                }
                            });
                        });
                    } else {
                        util.showToast("请授权后再使用");
                    }
                },
                error => {
                    console.log(error);
                }
            )
    }
    //提交用户信息
    submitUserInfo({
        headimgurl,
        username,
        sex
    }) {
        const url = util.api.info;
        const data = {
            token: util.token,
            headimgurl,
            username,
            sex
        };
        const method = "PUT";
        return util.sendRequest(url, method, data)
    }
    //提交验证码
    submitCode(phone, code, callBack) {
        const url = util.api.phone;
        const data = {
            token: util.token,
            phone: phone,
            code: code
        };
        const method = "PUT";
        util.sendRequest(url, method, data).then(
            res => {
                callBack(res)
            }
        )
    }

}
export {
    LoginModel
}